/*
 * Copyright (C) 2012, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.model;

import xowl.utils.config.Section;

/**
 *
 * @author Laurent WOUTERS
 */
public class DiagramLink extends DiagramElement {
    private String parentIRI;
    private String leftIRI;
    private String rightIRI;
    private String propertyIRI;
    private int originPort;
    private int targetPort;
    
    public String getParentIRI() { return parentIRI; }
    public String getLeftIRI() { return leftIRI; }
    public String getRightIRI() { return rightIRI; }
    public String getPropertyIRI() { return propertyIRI; }
    public int getOriginPort() { return originPort; }
    public int getTargetPort() { return targetPort; }
    
    public DiagramLink(String parentIRI, String leftIRI, String rightIRI, String propIRI, int originPort, int targetPort) {
        super(generateID("Link"));
        this.parentIRI = parentIRI;
        this.leftIRI = leftIRI;
        this.rightIRI = rightIRI;
        this.propertyIRI = propIRI;
        this.originPort = originPort;
        this.targetPort = targetPort;
    }
    
    public DiagramLink(String id, Section section) {
        super(id);
        this.parentIRI = section.getValue(id + ".piri");
        this.leftIRI = section.getValue(id + ".left");
        this.rightIRI = section.getValue(id + ".right");
        this.propertyIRI = section.getValue(id + ".property");
        String strorigin = section.getValue(id + ".origin");
        String strtarget = section.getValue(id + ".target");
        this.originPort = Integer.parseInt(strorigin);
        this.targetPort = Integer.parseInt(strtarget);
    }
    
    public void save(Section section) {
        section.addValue(id + ".piri", parentIRI);
        section.addValue(id + ".left", leftIRI);
        section.addValue(id + ".right", rightIRI);
        section.addValue(id + ".property", propertyIRI);
        section.addValue(id + ".origin", Integer.toString(originPort));
        section.addValue(id + ".target", Integer.toString(targetPort));
    }
}
